home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / mach / Machrules < prev    next >
Text File  |  1994-04-27  |  8KB  |  213 lines

  1. # Rules for MiG interfaces that want to go into the C library.
  2.  
  3. # Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
  4. # This file is part of the GNU C Library.
  5.  
  6. # The GNU C Library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Library General Public License
  8. # as published by the Free Software Foundation; either version 2 of
  9. # the License, or (at your option) any later version.
  10.  
  11. # The GNU C Library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. # Library General Public License for more details.
  15.  
  16. # You should have received a copy of the GNU Library General Public
  17. # License along with the GNU C Library; see the file COPYING.LIB.  If
  18. # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  19. # Cambridge, MA 02139, USA.
  20.  
  21. # Makefiles may define these variable before including this file:
  22. #    user-interfaces        Names of interfaces to put user stubs in for.
  23. #    server-interfaces    Names of interfaces to put server stubs in for.
  24. #    interface-library    Name of interface library to build and install.
  25. # This file sets:
  26. #    interface-headers    Names of generated interface header files.
  27. #    interface-routines    Names of generated interface routines.
  28. # All user stubs are put in individual files, prefixed with RPC_ (and the
  29. # function names prefixed with __), and a symbol-alias to the un-__'d form
  30. # generated; header for both is put in foo.h.  Server interfaces are
  31. # written to foo_server.c and foo_server.h; the server functions are called
  32. # _S_rpcname.
  33.  
  34. # Includers can also add to or modify `migdefines' to set MiG flags.
  35.  
  36. all:
  37.  
  38. # Make sure no value comes from the environment, since we append to it.
  39. # This is done also in ../Rules, but we append to the value before
  40. # including Rules, which changes the origin.
  41. ifneq    "$(findstring env,$(origin generated))" ""
  42. generated :=
  43. endif
  44.  
  45.  
  46. include ../Makeconfig
  47.  
  48. ifndef MIG
  49. MIG = mig
  50. endif
  51. MIGFLAGS = -DMACH_IPC_COMPAT=0 -DSTANDALONE -DTypeCheck=0 \
  52.        $(+includes) $(migdefines) -subrprefix __
  53.  
  54. .SUFFIXES: .defs    # Just to set specified_rule_matched.
  55.  
  56. define nl    # This is needed by *.ir.
  57.  
  58.  
  59. endef
  60. ifdef user-interfaces
  61. *.ir := $(addprefix $(objpfx),$(foreach if,$(user-interfaces),$(if).ir))
  62. ifndef inhibit_interface_rules
  63. include $(*.ir)
  64. endif
  65. ifneq "$(*.ir)" "$(wildcard $(*.ir))"
  66. # If any .ir file is missing, we will be unable to make all the deps.
  67. no_deps=t
  68. endif
  69. generated += $(*.ir:$(objpfx)%=%)
  70. endif
  71.  
  72.  
  73. # %.ir defines a variable `%-calls', which lists the RPCs defined by
  74. # %.defs, and a rule to build $(%-calls:%=RPC_$(%-userprefix)%.c) from
  75. # %.defs, where $(%-userprefix) is the user prefix given in %.defs.  We use
  76. # the kludgificacious method of defining a pattern rule to build files
  77. # matching patterns we are pretty damn sure will only match the particular
  78. # files we have in mind.  To be so damn sure, we use the silly names
  79. # RPC_*.c and the pattern R%C_*.c because using __*.c and _%*.c (or any
  80. # other useful pattern) causes the rule for `host_info' to also match
  81. # `xxx_host_info', and analogous lossage.
  82. #
  83. # While we're at it, we figure out the imports used by %.defs and give them
  84. # as dependencies of the object files for the generated RPC_*.c files.
  85. #
  86. # Depend on %.h just so they will be built from %.uh in the
  87. # makefile-rebuilding run which builds %.ir; otherwise, %.uh is built as an
  88. # intermediate in order to make %.ir and then removed before re-exec, when
  89. # %.uh is built all over again to build %.h.
  90. $(objpfx)%.ir: $(objpfx)%.uh $(objpfx)%.h
  91.     (awk "/^kern_return_t/ { printf \"$*-calls += %s\\n\", \$$2 }    \
  92.           /^#include/ { printf \"$*-imports += %s\\n\", \$$2 }" $<    ;\
  93.      echo '$$($*-calls:%=$$(objpfx)R\%C_%.c): $$(objpfx)$*.ustamp ;';\
  94.      echo '$$($*-calls:%=$$(objpfx)RPC_%.o): $$($*-imports:<%>=%)'    ;\
  95.     ) > $@-new
  96.     mv $@-new $@
  97. vpath Machrules ../mach    # Find ourselves.
  98.  
  99. # Not an implicit rule so the stamps are never removed as intermediates!
  100. $(patsubst %,$(objpfx)%.ustamp,$(user-interfaces)): $(objpfx)%.ustamp: %.defs
  101.     $(MIG) $< $(MIGFLAGS) $(user-MIGFLAGS) \
  102.            -prefix __ -i $(objpfx)tmp_ \
  103.            -server /dev/null -user /dev/null -header /dev/null
  104.     for call in $($*-calls); do \
  105.       ../move-if-change $(objpfx)tmp_$${call}.c $(objpfx)RPC_$${call}.c; \
  106.     done
  107.     touch $@
  108.  
  109. # Look for the server stub files where they will be written.
  110. vpath %_server.c $(addprefix $(objpfx),$(sort $(dir $(server-interfaces))))
  111.  
  112. # Build the server stubs in $(objdir).
  113. $(objpfx)%_server.c $(objpfx)%_server.h: %.defs
  114.     $(MIG) $< $(MIGFLAGS) $(server-MIGFLAGS) \
  115.            -prefix _S_ \
  116.            -user /dev/null -header /dev/null \
  117.            -server $(@:.h=.c) -sheader $(@:.c=.h)
  118.  
  119. # To get header files that declare both the straight and __ functions,
  120. # we generate two files and paste them together.
  121. $(objpfx)%.uh: %.defs; $(mig.uh)
  122. define mig.uh
  123. $(make-target-directory)
  124. $(MIG) $< $(MIGFLAGS) \
  125.        -header $@ -server /dev/null -user /dev/null
  126. endef
  127. $(objpfx)%.__h: %.defs; $(mig.__h)
  128. define mig.__h
  129. $(make-target-directory)
  130. $(MIG) $< $(MIGFLAGS) -prefix __ \
  131.        -header $@ -server /dev/null -user /dev/null
  132. endef
  133.  
  134. $(objpfx)%.h: $(objpfx)%.__h $(objpfx)%.uh
  135. # The last line of foo.__h is "#endif _foo_user_".
  136. # The first two lines of foo.uh are "#ifndef _foo_user_"/"#define _foo_user_".
  137.     (sed -e '$$d' $<; sed -e '1,2d' $(word 2,$^)) > $@-new
  138.     mv $@-new $@
  139.  
  140. if-calls.c := $(strip $(foreach if,$(user-interfaces),$($(if)-calls:%=%.c)))
  141. ifdef if-calls.c
  142. $(addprefix $(objpfx),$(if-calls.c)): $(objpfx)%.c: # Machrules
  143.     (echo '#include <gnu-stabs.h>'; \
  144.      echo 'symbol_alias (__$*, $*);') > $@-new
  145.     mv $@-new $@
  146. endif
  147.  
  148. interface-routines := $(foreach if,$(user-interfaces),            \
  149.                 $($(if)-calls)                \
  150.                 $(addprefix RPC_,$($(if)-calls)))    \
  151.               $(server-interfaces:%=%_server)
  152. interface-headers := $(user-interfaces:%=%.h) \
  153.              $(server-interfaces:%=%_server.h)
  154.  
  155. # Remove the generated user stub source and header files,
  156. # and don't distribute them.
  157. mach-generated = $(interface-routines:%=%.c) \
  158.          $(foreach h,$(interface-headers:%.h=%),$h.h $h.uh $h.__h)
  159. generated += $(mach-generated)
  160.  
  161. # These are needed to generate the dependencies.
  162. before-compile += $(interface-headers:%=$(objpfx)%)
  163.  
  164. # Don't let these be intermediate files and get removed.
  165. $(foreach h,$(interface-headers:%.h=$(objpfx)%),$h.h $h.__h $h.uh) :
  166. $(interface-routines:%=$(objpfx)%.c) :
  167.  
  168. # Convenient target to generate all the headers.
  169. .PHONY: interface-headers
  170. interface-headers: $(interface-headers)
  171.  
  172. # Don't automatically generate dependencies for the sources we generate.
  173. # There are likely to be a whole lot of them, and we know their
  174. # dependencies ahead of time anyway because they're boilerplate.
  175. omit-deps += $(interface-routines)
  176.  
  177. # Specify the static dependencies of the generated files.
  178. $(foreach if,$(user-interfaces),$($(if)-calls:%=$(objpfx)RPC_%.o))): \
  179.     mach/boolean.h mach/kern_return.h mach/message.h mach/notify.h \
  180.     mach/mach_types.h mach/mig_errors.h mach/mig_support.h mach/msg_type.h
  181. $(foreach if,$(user-interfaces),$($(if)-calls:%=$(objpfx)%.o)): ../gnu-stabs.h
  182. $(server-interfaces:%=$(objpfx)%.o): \
  183.     mach/boolean.h mach/kern_return.h mach/message.h mach/mig_errors.h \
  184.     mach/mig_support.h mach/std_types.h
  185. # The MiG-generated sources also depend on the imports in their .defs files.
  186. # These dependencies are generated into the .ir files above.
  187.  
  188. # If defined, $(interface-library) is `libNAME.a'.  It is to be a library
  189. # containing all the MiG-generated functions for the specified interfaces.
  190.  
  191. ifdef interface-library
  192.  
  193. $(interface-library)-objs := $(interface-routines:%=%.o)
  194.  
  195. install-lib += $(interface-library)
  196. extra-objs += $($(interface-library)-objs)
  197.  
  198. $(objpfx)$(interface-library): $(addprefix $(objpfx),\
  199.                        $($(interface-library)-objs))
  200. ifdef objdir
  201.     cd $(objdir); $(AR) cru$(verbose) $(@:$(objpfx)%=%) $(^:$(objpfx)%=%)
  202. else
  203.     $(AR) cru$(verbose) $@ $^
  204. endif
  205.     $(RANLIB) $@
  206.  
  207. lib-noranlib: $(objpfx)$(interface-library)
  208.  
  209. mostlyclean:
  210.     -rm -f $(objpfx)$(interface-library)
  211.  
  212. endif
  213.